/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.service;

import br.com.foxline.model.Groups;
import br.com.foxline.model.Users;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author ely
 */
@Stateless
public class GroupsService extends GenericService<Groups> {

    public GroupsService() {
        super(Groups.class);
    }

    public List<Groups> findGroupUsers(Users user) {
        System.out.println("Usuário "+ user.getName());
        String sql = "SELECT g FROM Groups g JOIN g.users u where u.id = :id";

        Query query = getEntityManager().createQuery(sql);
        query.setParameter("id",  user.getId());

        return query.getResultList();
    }
    
      public List<Groups> findGroups(Users u) { 
        String sql = "SELECT g FROM Users u JOIN u.groups g WHERE u.id = :id" ;
        Query query = getEntityManager().createQuery(sql);
        query.setParameter("id", u.getId());
        return (List<Groups>) query.getResultList();
    }
}
